package com.hzlx.feign2.fallback;

import com.hzlx.MesFinishedGoodsInventoryDto;
import com.hzlx.feign2.FinishInventory;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
@Slf4j
@Component
public class FinishInventoryFallbackFactory implements FallbackFactory<FinishInventory> {
    @Override
    public FinishInventory create(Throwable cause) {
        return new FinishInventory() {
            @Override
            public TableDataInfo list(MesFinishedGoodsInventoryDto mesFinishedGoodsInventoryDto) {
                // 记录错误日志
                log.error("调用成品库存服务失败: {}", cause.getMessage(), cause);

                // 返回降级数据
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setCode(500);
                tableDataInfo.setMsg("获取成品库存列表失败，服务暂时不可用");
                tableDataInfo.setRows(Collections.emptyList());
                tableDataInfo.setTotal(0L);
                return tableDataInfo;
            }
        };
    }
}
